package com.zystudio.func.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zystudio.func.R;
import com.zystudio.func.other.PolicyEntity;
import java.util.ArrayList;
import java.util.List;


/**
 * 小号列表
 *
 * */
public class AdapterPolicy extends BaseAdapter {

    private Context context;
    private List<PolicyEntity> mList;
    private OnItemOnClickListener onItemOnClickListener;


    public AdapterPolicy(Context context) {
        this.context = context;
        this.mList = new ArrayList<PolicyEntity>();

    }

    public AdapterPolicy(Context context, List<PolicyEntity> mList) {
        this.context = context;
        if (mList != null) {
            this.mList = mList;
        } else {
            this.mList = new ArrayList<>();
        }
    }


    public void addData(PolicyEntity str) {
        mList.add(str);
        notifyDataSetChanged();
    }

    public void replaceData(List<PolicyEntity> list) {
        if (list != null) {
            this.mList = list;
        }
        notifyDataSetChanged();
    }

    public void insertData(int index, PolicyEntity str) {
        mList.add(index, str);
    }

    public void setOnItemOnClickListener(OnItemOnClickListener l) {
        if (l != null) {
            this.onItemOnClickListener = l;
        }
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder holder = null;

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context)
                    .inflate(R.layout.adapter_activity_policy_item,
                            parent, false);
            holder.nameTv = view.findViewById(R.id.def_tv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        //判断是否是新号 新号只有一个小号
        holder.nameTv.setText(mList.get(position).getName());
        return view;
    }

    public interface OnItemOnClickListener {
        void onItemClicked();
    }

    private static class ViewHolder {
        TextView nameTv;
    }
}
